import * as vscode from 'vscode';

/**
 * 获取项目根目录
 */
export const getRootPath = (): string | void => {
	// 获取当前激活的工作区的根目录
	let workspaceFolder = vscode?.workspace?.workspaceFolders?.[0];

	if (workspaceFolder) {
		let projectRootPath = workspaceFolder.uri.fsPath;
		console.log(`项目根目录路径: ${projectRootPath}`);
		return projectRootPath;
	} else {
		// 如果没有打开任何工作空间，则处理这种情况
		vscode.window.showErrorMessage('请先打开一个工作区');
	}
};

/**
 * 获取已打开终端列表
 * @returns vscode.Terminal[]
 */
export const getTerminalOpened = (): readonly vscode.Terminal[] => {
	return vscode.window.terminals;
};

/**
 * 是否存在已打开终端
 */
export const isTerminalOpened = (): boolean => {
	return getTerminalOpened?.length > 0;
};
